DRY (Don’t Repeat Yourself) — принцип, согласно которому каждый фрагмент знания должен существовать в системе только в одном месте. Никакого копипаста и дублирующей логики.
Проблема: дублирование валидации
// Пример плохого кода if (user.Age < 18) throw new Exception("User must be at least 18");
...
if (user.Age < 18) return BadRequest("User must be at least 18");
При изменении правила — нужно помнить обновить его везде. Ловушка копипаста.
Решение: вынос логики в общее правило
public static class ValidationRules { public static bool IsAdult(User user) => user.Age >= 18; }
Теперь в коде
if (!ValidationRules.IsAdult(user)) throw new Exception("User must be at least 18");
// И в другом месте: if (!ValidationRules.IsAdult(user)) return BadRequest("User must be at least 18");
Альтернатива: использование FluentValidation или DataAnnotations
public class User { [Range(18, int.MaxValue, ErrorMessage = "User must be at least 18")] public int Age { get; set; } }
Где чаще всего нарушают DRY в .NET:
• Повторяющиеся SQL-запросы и фильтры • Повторение одинаковых exception'ов, логов, сообщений • Дублирование конфигурации • UI-формы и компоненты
DRY (Don’t Repeat Yourself) — принцип, согласно которому каждый фрагмент знания должен существовать в системе только в одном месте. Никакого копипаста и дублирующей логики.
Проблема: дублирование валидации
// Пример плохого кода if (user.Age < 18) throw new Exception("User must be at least 18");
...
if (user.Age < 18) return BadRequest("User must be at least 18");
При изменении правила — нужно помнить обновить его везде. Ловушка копипаста.
Решение: вынос логики в общее правило
public static class ValidationRules { public static bool IsAdult(User user) => user.Age >= 18; }
Теперь в коде
if (!ValidationRules.IsAdult(user)) throw new Exception("User must be at least 18");
// И в другом месте: if (!ValidationRules.IsAdult(user)) return BadRequest("User must be at least 18");
Альтернатива: использование FluentValidation или DataAnnotations
public class User { [Range(18, int.MaxValue, ErrorMessage = "User must be at least 18")] public int Age { get; set; } }
Где чаще всего нарушают DRY в .NET:
• Повторяющиеся SQL-запросы и фильтры • Повторение одинаковых exception'ов, логов, сообщений • Дублирование конфигурации • UI-формы и компоненты
Telegram’s stand out feature is its encryption scheme that keeps messages and media secure in transit. The scheme is known as MTProto and is based on 256-bit AES encryption, RSA encryption, and Diffie-Hellman key exchange. The result of this complicated and technical-sounding jargon? A messaging service that claims to keep your data safe.Why do we say claims? When dealing with security, you always want to leave room for scrutiny, and a few cryptography experts have criticized the system. Overall, any level of encryption is better than none, but a level of discretion should always be observed with any online connected system, even Telegram.
Telegram announces Search Filters
With the help of the Search Filters option, users can now filter search results by type. They can do that by using the new tabs: Media, Links, Files and others. Searches can be done based on the particular time period like by typing in the date or even “Yesterday”. If users type in the name of a person, group, channel or bot, an extra filter will be applied to the searches.